package com.kevin.Code.DP;

import java.io.InputStream;

/**
 * @author Vinlee Xiao
 * @Classname IsSubsequence
 * @Description Leetcode 392. 判断子序列 简单 动态规划
 * @Date 2021/10/5 15:06
 * @Version 1.0
 */
public class IsSubsequence {


    /**
     * @param s
     * @param t
     * @return
     */
    public boolean isSubsequence(String s, String t) {

        int m = s.length();
        int n = t.length();

        if (m == 0) {
            return true;
        }

        if (n == 0) {
            return false;
        }

        int[][] dp = new int[m + 1][n + 1];

        //当s为空时，
//        for (int i = 0; i < n + 1; i++) {
//            dp[0][i] = i;
//        }

        for (int i = 1; i < m + 1; i++) {

            for (int j = 1; j < n + 1; j++) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = dp[i][j - 1];
                }
            }
        }

        System.out.println(dp[m][n]);
        return dp[m][n] == m;
    }

    public static void main(String[] args) {
        IsSubsequence isSubsequence = new IsSubsequence();
        boolean subsequence = isSubsequence.isSubsequence("axc", "ahbgdc");
        System.out.println(subsequence);
    }
}
